#!/usr/bin/env python
# encoding: utf-8

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS

from config import config
import os

# app初始化,
# instance_relative_config 设置config文件可从Instance文件中查找
app = Flask(__name__, instance_relative_config=True)

# 配置文件导入
if "FLASK_WEB" in os.environ:
    app.config.from_object(config[os.environ['FLASK_WEB']])
    print("当前环境变量值:%s"%os.environ['FLASK_WEB'])
else:
    app.config.from_object(config['development'])
    print("当前环境变量值:development")

db = SQLAlchemy()
cors = CORS()

# 数据库管理
db.init_app(app)
# 跨域问题
cors.init_app(app, supports_credentials=True)

# 后面需要调用db的，导入时需要放在db初始化完成之后
from app.views.admin import admin
admin.init_app(app)

'''
统一拦截处理和统一错误处理
'''
#  from app.interceptor.ApiInterceptor import  *

'''
蓝图功能，对所有的url进行蓝图功能配置
'''

from app.views.webapi import route_api
from app.views.index import index

app.register_blueprint(route_api, url_prefix='/api')
app.register_blueprint(index, url_prefix='/')


